using System;
using System.Web;
using System.IO;
using System.Web.Security;
using System.Web.UI.WebControls;
using System.Web.Configuration;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint;

namespace CKS.WindowsLiveAuthentication
{
    /// <summary>
    /// </summary>
    public partial class liveinfo : System.Web.UI.Page
    {
        protected InputFormTextBox tbDisplayName;
        protected InputFormTextBox tbEmail;
        protected InputFormTextBox tbAboutMe;
        protected InputFormTextBox tbPicture;
        protected InputFormTextBox tbDepartment;
        protected InputFormTextBox tbJobTitle;
        protected InputFormTextBox tbSipAddress;
        protected Button butSubmit;
        protected string redir;

        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.Load += new EventHandler(Page_Load);
        }
        #endregion

        private void Page_Load(object sender, System.EventArgs e)
        {
            redir = Request.QueryString["Source"];

            if (redir == null)
            {
                redir = SPContext.Current.Web.Url;
            }

            if (User.Identity.IsAuthenticated)
            {
                if (!IsPostBack)
                {
                    BlogUserProfile bup = BlogUserProfile.GetUser(User.Identity.Name);

                    if (bup != null)
                    {
                        tbDisplayName.Text = bup.DisplayName;
                        tbEmail.Text = bup.Email;
                        tbAboutMe.Text = bup.AboutMe;
                        tbPicture.Text = bup.Picture;
                        tbDepartment.Text = bup.Department;
                        tbJobTitle.Text = bup.JobTitle;
                        tbSipAddress.Text = bup.SipAddress;
                    }
                    else
                    {
                        Response.Redirect(redir);
                    }
                }
            }
            else
            {
                Response.Redirect(redir);
            }
        }

        public void Submit_Click(Object sender, EventArgs e)
        {
            if (User.Identity.IsAuthenticated)
            {
                BlogUserProfile bup = BlogUserProfile.GetUser(User.Identity.Name);
                bup.DisplayName = tbDisplayName.Text;
                bup.Email = tbEmail.Text;
                bup.AboutMe = tbAboutMe.Text;
                bup.Picture = tbPicture.Text;
                bup.Department = tbDepartment.Text;
                bup.JobTitle = tbJobTitle.Text;
                bup.SipAddress = tbSipAddress.Text;

                bup.Update();
                Response.Redirect(redir);
            }
        }
    }
}

